﻿@model HuaHan.WorkTicket.Domain.Group

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h5>角色组设定</h5>
</div>
<div class="modal-body" >
    @using (Ajax.BeginForm("CreateAndEdit", null, new AjaxOptions { HttpMethod = "POST", OnSuccess = "SuccessCreate", OnFailure = "FailureCreate" }, new { @class = "form-horizontal",id="form1"}))
    {
        @Html.ValidationSummary(true)        
        @Html.HiddenFor(c => c.GroupID)
        @Html.HiddenFor(c => c.CreatedAt)
        @Html.HiddenFor(c => c.UpdatedAt)
        <div class="control-group">
            @Html.LabelFor(c => c.Name, new { @class = "control-label" })
            <div class="controls">
                @Html.TextBoxFor(c => c.Name, new { @class = "input-xlarge focused" })
                @Html.ValidationMessageFor(c => c.Name)
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(c => c.Description, new { @class = "control-label" })
            <div class="controls">
                @Html.TextBoxFor(c => c.Description, new { @class = "input-xlarge focused" })
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(c => c.IsValid, new { @class = "control-label" })
            <div class="controls">
                <label class="checkbox">
                    @Html.CheckBoxFor(c => c.IsValid, new { @class = "input-xlarge focused" })
                </label>
            </div>
        </div>

        <div class="control-group">
            @Html.LabelFor(c => c.Remark, new { @class = "control-label" })
            <div class="controls">
                @Html.TextAreaFor(c => c.Remark, new { @class = "input-xlarge focused" })
            </div>
        </div>


        <div class="form-actions">
            <button type="submit" class="btn btn-primary" id="btnSubmit">保存</button>
            <input type="button" class="btn" id="btnCancel" value="取消" />
        </div>
    }

</div>

<script>
    $(document).ready(function () {
        $("#form1").validate({
            rules: {
                Name: {
                    required: true,
                    remote: {
                        type: "POST",
                        url: "/Group/CheckNameExisted",
                        dataType: "json",
                        data: {
                            Name: function () { return $("#Name").val(); },
                            ID: function () { return $("#GroupID").val(); }
                        }
                    }
                }

            },
            messages: {
                required: "名称不能为空",
                remote: $.format("该角色组已存在！")
            },
            errorClass: "error",
            errorElement:"div"
        });

        $("#btnSubmit").click(function () {
            if ($("#form1").validate()==false) {
                return;
            }
        });

        $("#btnCancel").click(function () {
            $('#createAndEditModal').modal('hide');
            return;
        });

    });
</script>
@*    <div class="modal-footer">
        <a href="#" class="btn">关闭</a>
        <a href="#" class="btn btn-primary">Save changes</a>
    </div>*@